package com.oc.claimobs.bb.model;

import java.io.IOException;

import ar.com.lemil.j2me.serialization.IObjectInputStream;
import ar.com.lemil.j2me.serialization.IObjectOutputStream;
import ar.com.lemil.j2me.serialization.ISerializable;

import com.oc.utils.TextUtils;

public class Info implements ISerializable {

	private String nombre = "";
	private String apellido = "" ;
	private String telefono = "";
	private String documento = "";
	private String tipodoc = "";
	
	private String email = "";

	private String installDate = "" + System.currentTimeMillis();
	private String lastClaimId = "";
	
	private String url = "";
	
	private String carrier = "";
	
	public String getCarrier() {
		return carrier;
	}

	public void setCarrier(String carrier) {
		this.carrier = carrier;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getNombre() {
		return nombre;
	}

	public void setNombre(String nombre) {
		this.nombre = nombre;
	}

	public String getApellido() {
		return apellido;
	}

	public void setApellido(String apellido) {
		this.apellido = apellido;
	}

	public String getTelefono() {
		return telefono;
	}

	public void setTelefono(String telefono) {
		this.telefono = telefono;
	}

	public String getDocumento() {
		return documento;
	}

	public void setDocumento(String documento) {
		this.documento = documento;
	}

	public String getTipodoc() {
		return tipodoc;
	}

	public void setTipodoc(String tipodoc) {
		this.tipodoc = tipodoc;
	}

	public String getInstallDate() {
		return installDate;
	}

	public void setInstallDate(String installDate) {
		this.installDate = installDate;
	}

	public String getLastClaimId() {
		return lastClaimId;
	}

	public void setLastClaimId(String lastClaimId) {
		this.lastClaimId = lastClaimId;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public void readObject(IObjectInputStream iobjectinputstream)
			throws IOException, ClassNotFoundException {
		String data = iobjectinputstream.readASC();
		String[] pieces = TextUtils.split(data, "&");

		for (int i = 0; i < pieces.length; i++) {
			String[] s = TextUtils.split(pieces[i], "=");
			if (s.length > 1) {
				String k = s[0];
				String v = pieces[i].substring(k.length() + 1);
				if (k.equalsIgnoreCase("apellido")) {
					setApellido(v);
				}
				if (k.equalsIgnoreCase("documento")) {
					setDocumento(v);
				}
				if (k.equalsIgnoreCase("installDate")) {
					setInstallDate(v);
				}
				if (k.equalsIgnoreCase("lastClaimId")) {
					setLastClaimId(v);
				}
				if (k.equalsIgnoreCase("nombre")) {
					setNombre(v);
				}
				if (k.equalsIgnoreCase("telefono")) {
					setTelefono(v);
				}
				if (k.equalsIgnoreCase("tipodoc")) {
					setTipodoc(v);
				}
				if (k.equalsIgnoreCase("url")){
					setUrl(v);
				}
				if (k.equalsIgnoreCase("carrier")){
					setCarrier(v);
				}
				if (k.equalsIgnoreCase("email")){
					setEmail(v);
				}
			}
		}

	}

	public void writeObject(IObjectOutputStream iobjectoutputstream)
			throws IOException {
		iobjectoutputstream.writeASC(this.toString());
	}

	public String toString() {

		StringBuffer data = new StringBuffer();
		data.append("apellido=");
		data.append(this.apellido);
		data.append("&documento=");
		data.append(this.documento);
		data.append("&installDate=");
		data.append(this.installDate);
		data.append("&lastClaimId=");
		data.append(this.lastClaimId);
		data.append("&nombre=");
		data.append(this.nombre);
		data.append("&telefono=");
		data.append(this.telefono);
		data.append("&tipodoc=");
		data.append(this.tipodoc);
		data.append("&url=");
		data.append(this.url);
		data.append("&carrier=");
		data.append(this.carrier);
		data.append("&email=");
		data.append(this.email);
		return data.toString();
	}

}

